package tracking.service;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;

import tracking.LTEConstants;
import tracking.Utils;
import tracking.dto.Detailsdto;
import tracking.dto.Trackingdto;
import tracking.dto.Userdto;

@Path("/test")
public class TestManager {
	private static final String TAG = "MenuManager";
	// log4j value
	
	
	@GET
	@Path("/1")
	/**
	 * return list menu for android from locationId
	 * @param location is location device
	 * @return a json
	 */
	public String getMenuInfo2() {
		Userdto dto = new Userdto("u1", "123456");
		return Utils.getStringFromUserdto(dto);
	}
	
	@POST
	@Path("/1")
	/**
	 * return list menu for android from locationId
	 * @param location is location device
	 * @return a json
	 */
	public String getMenuInfo3(@FormParam("value") String value) {
		System.out.println("NECVN>>>" + TAG + "-" + "value:" + value);
		Userdto dto = new Userdto("u1", "123456");
		return Utils.getStringFromUserdto(dto);
	}
	@POST
	@Path("/getMenu")
	/**
	 * return list menu for android from locationId
	 * @param location is location device
	 * @return a json
	 */
	public String getMenuInfo(@FormParam("data") String data) {
		return "sonnt";
	}
	
	@GET
	@Path("/trackingdto")
	/**
	 * return list menu for android from locationId
	 * @param location is location device
	 * @return a json
	 */
	public String trackingdto() {
		Trackingdto dto = new Trackingdto();
		dto.setYear(2013);
		dto.setMonth(12);
		dto.setDay(3);
		dto.setType(LTEConstants.TYPE_DAY);
		dto.setUserId("u1");
		dto.setDeviceId("ss1");
		dto.setArrange(LTEConstants.ARRANGE_YES);
//		Calendar c = Calendar.getInstance();
//		c.set(Calendar.DATE, 8);
//		
//		Calendar c2 = Calendar.getInstance();
//		c2.set(Calendar.DATE, 12);
		
//		dto.setStart(c.getTimeInMillis());
//		dto.setEnd(c2.getTimeInMillis());
		dto.setStart("2013-11-28");
		dto.setEnd("2013-12-04");
		
		return Utils.getStringFromTrackingdto(dto);
	}
	
	@GET
	@Path("/insert")
	/**
	 * return list menu for android from locationId
	 * @param location is location device
	 * @return a json
	 */
	public String insertT() {
		Trackingdto dto = new Trackingdto();
		
		dto.setUserId("u1");
		dto.setDeviceId("ss1");
		dto.setTrafficSum(101);
		List<Detailsdto> list = new ArrayList<Detailsdto>();
		
		Detailsdto d = new Detailsdto();
		d.setAppname("facebook");
		d.setAppPackage("f.a.f");
		Calendar c = Calendar.getInstance();
		Calendar ca = Calendar.getInstance();
		c.clear();
		c.set(Calendar.YEAR, ca.get(Calendar.YEAR));
		c.set(Calendar.MONTH, ca.get(Calendar.MONTH));
		c.set(Calendar.DAY_OF_MONTH, ca.get(Calendar.DAY_OF_MONTH));
		c.set(Calendar.HOUR_OF_DAY, ca.get(Calendar.HOUR_OF_DAY));
		d.setLongtime(c.getTimeInMillis());
		d.setTime(Utils.getTimeUpdateDB(ca.getTimeInMillis()));
		d.setTraffic(10000);
		
		Detailsdto d1 = new Detailsdto();
		d1.setAppname("click");
		d1.setAppPackage("c.l");
		d1.setLongtime(c.getTimeInMillis());
		d1.setTime(Utils.getTimeUpdateDB(ca.getTimeInMillis()));
		d1.setTraffic(20000);
		
		Detailsdto d2 = new Detailsdto();
		d2.setAppname("olaola");
		d2.setAppPackage("c.l,2");
		c.set(Calendar.HOUR_OF_DAY, 21);
		d2.setLongtime(c.getTimeInMillis());
		d2.setTime(Utils.getTimeUpdateDB(ca.getTimeInMillis()));
		d2.setTraffic(20000);
		
		list.add(d);
		list.add(d1);
		list.add(d2);
		
		dto.setList(list);
		
		System.out.println("date:" + System.currentTimeMillis());
		
		
		return Utils.getStringFromTrackingdto(dto);
	}
	
	@POST
	@Path("/post")
	public String mypost(){
		return "mypost";
				
				
				
	}
}
